<template>
  <div class="new_left">
    <div class="title">
      <Title1 title="统计数据"></Title1>
    </div>
    <div class="div1">
      <div class="title">
        <Title2 title="智游舒城小程序" title1="周访问量" :title2="11926" />
        <div class="div1_con">
          <div
            v-for="(item, index) in allNumsArr"
            :key="index"
            class="div1_item"
          >
            <p class="item_num">{{ item.num }}</p>
            <p class="item_title">{{ item.title }}</p>
          </div>
        </div>
      </div>
    </div>
    <div class="div2">
      <div class="title"><Title2 title="甄选百货货物售卖数据统计" /></div>
      <div class="div2_con">
        <div
          v-for="(item, index) in soldNumsArr"
          :key="index"
          class="div2_item"
        >
          <img :src="getImgSrc(index)" alt="" />
          <p>
            <span class="d2_item_num">{{ item.num }}</span>
            <span>{{ item.title }}</span>
          </p>
        </div>
      </div>
    </div>
    <div class="div3">
      <div class="title"><Title2 title="产品销售种类排行 TOP5" /></div>
      <div id="top5Num" style="width: 100%; height: 100%"></div>
    </div>
    <div class="div4">
      <div class="title"><Title2 title="票务系统售票数据统计" /></div>
      <div class="div4_total">
        <div class="d4_con" v-for="(i, index) in sellTicketArr" :key="index">
          <i class="d4_title">{{ i.title }}</i>
          <p class="d4_num">{{ i.num }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import * as echarts from "echarts";

import Title1 from "./Title1.vue";
import Title2 from "./Title2.vue";

export default {
  components: {
    Title1,
    Title2,
  },
  props: {},
  computed: {},
  watch: {},
  data() {
    return {
      allNumsArr: [
        { num: 568352, title: "本年度访问量" },
        { num: 62230, title: "总订单量" },
        { num: 1350860, title: "总营业额" },
        { num: 2357, title: "入驻商家" },
      ],
      soldNumsArr: [
        { num: 350, title: "总访问量（人）" },
        { num: 23984234, title: "销售总金额（万元）" },
        { num: 2342342, title: "订单数（笔）" },
        { num: 235423, title: "会员数（人）" },
      ],
      // 前5排行
      top5NumCharts: null,
      // 售票
      sellTicketArr: [
        { num: 146, title: "今日售票（张）" },
        { num: 4526, title: "本月售票（张）" },
        { num: 67890, title: "年度售票（张）" },
        { num: 3423, title: "今日收入（元）" },
        { num: 106113, title: "本月收入（元）" },
        { num: 1485582, title: "本年度收入（元）" },
      ],
    };
  },
  methods: {
    setTop5Num() {
      this.top5NumCharts = echarts.init(document.getElementById("top5Num"));

      let option = {
        color: ["#1DA7C0"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        grid: {
          left: "2%",
          right: "2%",
          bottom: "20%",
          top: "18%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            data: ["土特产", "手工艺品", "美食小吃", "纺织工艺品", "纪念品"],
            axisTick: {
              show: false,
              interval: 0,
              alignWithLabel: true,
            },
            axisLine: {
              show: false,
              lineStyle: {
                color: "#404f60",
              },
            },
            axisLabel: {
              interval: 0,
              textStyle: {
                color: "#fff",
              },
            },
          },
        ],
        yAxis: [
          {
            // 单位
            name: "万元",
            nameLocation: "end",
            nameTextStyle: {
              color: "#fff",
              padding: [0, 20, 0, 0],
            },

            type: "value",
            axisLine: {
              show: false,
              lineStyle: {
                color: "#404f60",
              },
            },
            axisLabel: {
              textStyle: {
                color: "#fff",
              },
            },
            // 分割线
            splitLine: {
              show: true,
              lineStyle: {
                color: "#233347",
                width: 1,
                type: "dashed",
              },
            },
          },
        ],
        series: [
          {
            name: "数量",
            type: "bar",
            barWidth: "36%",
            data: [52, 40, 33, 29, 14],
          },
        ],
      };
      this.top5NumCharts.setOption(option);

      window.addEventListener("resize", () => {
        this.top5NumCharts?.resize();
      });
    },

    getImgSrc(index) {
      return require(`@/assets/images/newImg/${index}.png`);
    },
  },
  mounted() {
    this.setTop5Num();
  },
  created() {},
  destroyed() {
    this.top5NumCharts?.dispose();
    this.top5NumCharts = null;
  },
};
</script>

<style lang="scss" scoped>
@import "@/utils/px2vwvh.scss";

.new_left {
  width: 100%;
  height: 100%;
  @include px2vw(padding-left, 17);
  @include px2vw(padding-right, 17);
  @include px2vh(padding-top, 21);
  @include px2vh(padding-bottom, 21);
  .title {
    width: 100%;
    @include px2vh(height, 46);
  }
  .div1 {
    width: 100%;
    @include px2vh(height, 154);
    .div1_con {
      width: 100%;
      @include px2vh(height, 40);
      @include px2vh(margin-top, 27);
      display: flex;
      align-items: center;
      justify-content: space-between;

      color: rgba(6, 230, 232, 1);
      @include px2font(18);
      text-align: center;

      .item_title {
        @include px2vh(margin-top, 10);
        @include px2font(12);
        color: #fff;
      }
      .div1_item {
        flex: 1;
        background-image: url(~@/assets/images/newImg/line.png);
        background-repeat: no-repeat;
        background-position: center right;
        &:last-child {
          background-image: none;
        }
      }
    }
  }
  .div2,
  .div3,
  .div4 {
    width: 100%;
    @include px2vh(height, 230);
  }
  .div2 {
    .div2_con {
      display: flex;
      flex-wrap: wrap;
      .div2_item {
        width: 50%;
        display: flex;
        align-items: center;

        @include px2vh(margin-top, 18);
        @include px2vh(height, 60);
        img {
          height: 100%;
          @include px2vw(width, 63);
          @include px2vw(margin-right, 15);
        }
        p {
          span {
            display: block;
            color: rgba(255, 255, 255, 0.8);
            @include px2font(12);
          }
          .d2_item_num {
            color: rgba(6, 230, 232, 1);
            @include px2font(20);
          }
        }
      }
    }
  }

  .div4 {
    .div4_total {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-wrap: wrap;
      .d4_con {
        @include px2vh(margin-top, 8);
        @include px2vh(margin-bottom, 16);
        width: 30%;
        text-align: center;
        color: rgba(6, 230, 232, 1);
        @include px2font(20);
        .d4_title {
          display: block;
          width: 100%;
          height: 100%;
          padding: 4% 0;
          color: rgba(255, 255, 255, 0.8);
          @include px2font(12);
          background-image: url(~@/assets/images/newImg/piao_total.png);
          background-repeat: no-repeat;
          background-position: center center;
          background-size: 100% 100%;
        }
        .d4_num {
          @include px2vh(margin-top, 8);
        }
      }
    }
  }
}
</style>
